package com.sunny.shop.api.v1;

import com.sunny.shop.core.LocalUser;
import com.sunny.shop.core.interceptors.ScopeLevel;
import com.sunny.shop.dto.UserDTO;
import com.sunny.shop.exception.httpe.Success;
import com.sunny.shop.model.User;
import com.sunny.shop.service.UserServiceImpl;
import com.sunny.shop.vo.UserSimplifyVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController{
    @Autowired
    private UserServiceImpl userService;

    @ScopeLevel
    @PostMapping("")
    public void saveUserInfo(@RequestBody UserDTO userDTO){
        userService.saveUserInfo(userDTO);
        throw new Success(90002);
    }

    @ScopeLevel
    @GetMapping("")
    public UserSimplifyVO saveUserInfo(){
        Long id = LocalUser.getUser().getId();
        User user = userService.getUserByUid(id);
        UserSimplifyVO userVO = new UserSimplifyVO();
        BeanUtils.copyProperties(user, userVO);
        return userVO;
    }
}
